<?php
/*!
 * Theme Name:One Nav
 * Theme URI:https://www.iotheme.cn/
 * Author:iowen
 * Author URI:https://www.iowen.cn/
 */
if ( ! defined( 'ABSPATH' ) ) { exit; }
get_header(); ?>


<?php 
include( get_theme_file_path('/templates/sidebar-nav.php') );
?>
<div class="main-content flex-fill single">
<?php get_template_part( 'templates/header','banner' ); ?>
<div id="content" class="container my-4 my-md-5">
                <?php 
                $sites_type = get_post_meta(get_the_ID(), '_sites_type', true);
                if($sites_type == "down") include( get_theme_file_path('/templates/content-down.php') );
                else include( get_theme_file_path('/templates/content-site.php') );
                ?>

                <h4 class="text-gray text-lg my-4"><i class="site-tag iconfont icon-tag icon-lg mr-1" ></i><?php echo get_the_title()?>的<?php _e('相关导航','i_theme') ?></h4>
                <div class="row mb-n4 customize-site"> 
                    <?php get_template_part( 'templates/related','sites' ); ?>
                </div>
    	        <?php 
    	        if ( comments_open() || get_comments_number() ) :
			    	comments_template();
    	        endif; 
    	        ?>
</div>
<script type='text/javascript'>
    $(document).ready(function(){
        if($(".security_check.d-none").length>0) {
            $("#check_s").show();
            $("#country").show();
            if(!$("#country").hasClass('loadcountry'))
                ipanalysis($(".security_check.d-none").data('ip'));
        }
        else{
            $("#check_s").remove();
            $("#country:not(.loadcountry)").remove();
        }
    });
    var tim=1;
    var timer = setInterval("tim++",100); 
    function check(url){
        var msg ="";
        if(tim>100) { 
            clearInterval(timer);
            $.getJSON('//api.iowen.cn/webinfo/get.php?url='+url,function(data){
                if(data.code==0){
                    msg = '<i class="iconfont icon-crying-circle mr-1" style="color:#f12345"></i><?php _e('链接超时，网站可能下线了，请点击直达试试','i_theme') ?> <i class="iconfont icon-crying"></i>';
                    updateStatus(false);
                }
                else{
                    msg = '<i class="iconfont icon-smiley-circle mr-1" style="color:#f1b223"></i><?php _e('墙外世界需要梯子','i_theme') ?> <i class="iconfont icon-smiley"></i>';
                    updateStatus(true);
                }
                $("#check_s").html(msg); 
            }).fail(function () {
                msg = '<i class="iconfont icon-crying-circle mr-1" style="color:#f12345"></i><?php _e('链接超时，网站可能下线了，请点击直达试试','i_theme') ?> <i class="iconfont icon-crying"></i>';
                $("#check_s").html(msg); 
                updateStatus(false);
            });
            clearInterval(timer);
        }
        else {
             msg = '<i class="iconfont icon-smiley-circle mr-1" style="color:#26f123"></i><?php _e('链接成功:','i_theme') ?>' + tim/10 + '<?php _e('秒','i_theme') ?>';
            $("#check_s").html(msg+'<a href="#respond" style="margin-left:8px;color:#aaa" title="该网站遇到问题？请留言告知。">遇到问题？</a>');
            updateStatus(true);
            clearInterval(timer);
        }
    } 
    function ipanalysis(ip){
        $.getJSON('//api.iotheme.cn/ip/get.php?ip='+ip,function(data){
            if(data.status == 'success'){
                $("#country").html('<i class="iconfont icon-globe mr-1"></i>'+ data.country); 
                $.ajax({
		        	url : "<?php echo admin_url( 'admin-ajax.php' ) ?>",  
		        	data : {
		        		action: "io_set_country",
		        		country: data.country,
		        		id: <?php echo $post->ID ?>
		        	},
		        	type : 'POST',
                    error:function(){ 
                        console.log('<?php _e('网络错误','i_theme') ?> --.'); 
                    }
		        });
            }
            else
                $("#country").html('<i class="iconfont icon-crying-circle mr-1"></i><?php _e('查询失败','i_theme') ?>'); 
        }).fail(function () {
            $("#country").html('<i class="iconfont icon-crying-circle"></i>'); 
        });
    }
    function updateStatus(isInvalid){ 
		$.ajax({
			url : "<?php echo admin_url( 'admin-ajax.php' ) ?>",  
			data : {
				action: "link_failed",
				is_inv: isInvalid,
				post_id: <?php echo $post->ID ?>
			},
			type : 'POST',
            error:function(){ 
                console.log('<?php _e('网络错误','i_theme') ?> --.'); 
            }
		});
    }
</script>
<?php get_footer(); ?>